{include file="public/nheader" /}
<div class="layui-fluid layui-bg-white">
    <form action="{:url()}" class="layui-form layui-form-fixed">
        <div class="layui-form-item">
            <label class="layui-form-label">
                <font color="red">* </font>活动名称
            </label>
            <div class="layui-input-block">
                <input type="text" id="title" name="title" required="" lay-verify="required" autocomplete="off"
                    class="layui-input" value="{$row.title|default=''}" placeholder="">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">
                <font color="red">* </font>参与人数
            </label>
            <div class="layui-input-block">
                <input type="number" id="people" name="people" required="" lay-verify="required" autocomplete="off"
                    class="layui-input" value="{$row.people|default='1'}" placeholder="">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">
                <font color="red">* </font>状态
            </label>
            <div class="layui-input-block">
                <input type="radio" name="status" value="1" title="开启" {if !empty($row.status) &&
                    $row.status==1}checked{/if}>
                <input type="radio" name="status" value="2" title="结束" {if !empty($row.status) &&
                    $row.status==2}checked{/if}>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">
                <font color="red">* </font>结束时间
            </label>
            <div class="layui-input-block">
                <input type="text" name="sxtime" autocomplete="off" data-format="yyyy-MM-dd" data-type="date"
                    lay-datetime="" class="layui-input" value="{$row.sxtime|default=''}">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">
                <font color="red">* </font>使用说明
            </label>
            <div class="layui-input-block">
                <textarea name="contents"
                    class="layui-textarea" />{$row.contents|default='示例:本券仅可在持码人服务区域内使用,其它区域无法使用本券。如有疑问,请联系持码服务人员。本活动含:小白鞋清洗券*1,网面鞋清洗券*1,儿童鞋清洗券*1,跑步鞋清洗券*1,满20减2服务券一张(有效期30天),每人仅可领取一次'}</textarea>
            </div>
        </div>
        <div class="layui-card layui-form">
            <label class="layui-form-label">
                满减券
            </label>
            <div class="layui-card-body">
                <div class="layui-input-block">
                    <a class="layui-btn layui-btn-btn layui-btn-sm layui-btn-normal" onclick="addtable2()">添加</a>
                    <table class="layui-table layui-form" style="border:1px solid #ccc;" id="table2"
                        lay-filter="table2">
                        <thead>
                            <tr>
                                <td>
                                    <div class="layui-table-cell">使用条件金额(单位:元)</div>
                                </td>
                                <td>
                                    <div class="layui-table-cell">抵扣金额(单位:元)</div>
                                </td>
                                <td>
                                    <div class="layui-table-cell">有效时长(单位:天)</div>
                                </td>
                                <td>
                                    <div class="layui-table-cell">操作</div>
                                </td>
                            </tr>
                        </thead>
                        <tbody>
                            {if !empty($row.coupon.coupon)}
                            {foreach $row.coupon.coupon as $k => $v}
                            <tr>
                                <td><input required="" lay-verify="required" type="text" id="layui-input"
                                        class="layui-input" name="coupon[coupon][{$k}][getmoney]" value="{$v.getmoney}">
                                </td>
                                <td><input required="" lay-verify="required" type="text" id="layui-input"
                                        class="layui-input" name="coupon[coupon][{$k}][money]" value="{$v.money}">
                                </td>
                                <td><input required="" lay-verify="required" type="text" id="layui-input"
                                        class="layui-input" name="coupon[coupon][{$k}][days]" value="{$v.days}">
                                </td>
                                <td>
                                    <a class="layui-btn layui-btn-danger layui-btn-xs del2">删除</a>
                                </td>
                            </tr>
                            {/foreach}
                            {/if}
                        </tbody>
                    </table>
                </div>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">
                项目次数
            </label>
            <div class="layui-input-block">
                <table class="layui-table">
                    <colgroup>
                        <col width="150">
                        <col width="150">
                    </colgroup>
                    <thead>
                        <tr>
                            <th>项目名称</th>
                            <th>清洗次数</th>
                        </tr>
                    </thead>
                    <tbody id="tableget">
                        {foreach $product as $pro}
                        <tr>
                            <td>{$pro.title}(￥{$pro.price})</td>
                            <td><input name="coupon[getnumber][{$pro.id}]" type="number"
                                    value="{$row.coupon.getnumber[$pro.id]|default='0'}" class="layui-input" /></td>
                        </tr>
                        {/foreach}
                        {if empty($product)}<tr>
                            <td>暂无项目,请先添加产品或选择代理</td>
                            <td></td>
                        </tr>{/if}
                    </tbody>
                </table>
            </div>
        </div>
        <!-- <div class="layui-form-item">
            <label class="layui-form-label">
                <font color="red">* </font>满减条件说明
            </label>
            <div class="layui-input-block">
                <textarea name="protocol"
                    class="layui-textarea" />{$row.protocol|default='本券满*元可抵扣*元，有效期*天，请务必在有效期内使用'}</textarea>
            </div>
        </div> -->
        <div class="layui-footer layui-form-item layui-center ">
            <input type="hidden" value="{$row['id']|default='0'}" name="id" />
            <button class="layui-btn" lay-filter="submitIframe" type="button" lay-submit>提交</button>
            <button class="layui-btn layui-btn-primary" type="button" sa-event="closeDialog">取消</button>
        </div>
    </form>
</div>
{include file="public/nfooter" /}
<script type="text/javascript" src="https://cdn.bootcdn.net/ajax/libs/jquery/3.6.0/jquery.js"></script>
<script>
    layui.use(['form', 'jquery', 'layedit', 'admin', 'content'], function () {
        var form = layui.form;
        var admin = layui.admin;
        var jquery = layui.jquery;
        // 渲染富文本编辑器
        var layedit = layui.layedit;
        var content = layui.content;
        content.tinymce('contents');
        content.tinymce('protocol');
    });
    function addtable2() {
        var i = $('#table2 tbody tr').length;
        //你要添加的html
        var html = '<tr>' +
            '<td><input required="" lay-verify="required" type="text" id="layui-input" class="layui-input" name="coupon[coupon][' + i + '][getmoney]" value=""></td>' +
            '<td><input required="" lay-verify="required" type="text" id="layui-input" class="layui-input" name="coupon[coupon][' + i + '][money]" value=""></td>' +
            '<td><input required="" lay-verify="required" type="text" id="layui-input" class="layui-input" name="coupon[coupon][' + i + '][days]" value=""></td>' +
            '<td><a class="layui-btn layui-btn-danger layui-btn-xs del2" >删除</a></td></tr>';
        $(html).appendTo($('#table2 tbody:last'));
        layui.use(['form'], function () {
            $ = layui.jquery;
            var form = layui.form;
            form.render();
        });
    };
    $('body').on('click', '.del2', function () {
        $(this).closest('tr').remove();
    });
</script>